﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.UI;
using MVC4App.Areas.Administrators.Models;
using MVC4App.Repositories.Core.Security;
using MVC4App.Repositories.Implementations.Security;
using Newtonsoft.Json;

namespace MVC4App.Areas.Administrators.Controllers
{
    public class SharedController : AdminBaseController
    {
        //
        // GET: /Administrators/Shared/
        private readonly ISiteRepository _siteRepository;
        private readonly IPermissionRepository _permissionRepository;
        private readonly IPermissionInSiteRepository _permissionInSiteRepository;
        private static int _userId;
        public SharedController()
        {
            _siteRepository = new SiteRepository();
            _permissionRepository = new PermissionRepository();
            _permissionInSiteRepository=new PermissionInSiteRepository();
        }
        //[OutputCache(Duration = 3600)]
        /// <summary>
        /// Tools the bar.
        /// </summary>
        /// <returns></returns>
        public ActionResult ToolBar()
        {
            int.TryParse(Session["UserId"].ToString(), out _userId);
            var result = _siteRepository.GetList(_userId,0);
            return PartialView(result.ToModel());
        }
        //[OutputCache(Duration = 3600)]
        /// <summary>
        /// Navigations the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public PartialViewResult Navigation(int id)
        {
            var result = _siteRepository.GetList(_userId, id);            
            return PartialView(result.ToModel());
        }
        /// <summary>
        /// Subs the navigation.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public PartialViewResult SubNavigation(int id)
        {
            var result = _siteRepository.GetList(_userId, id);
            return result.Count>0 ? PartialView(result.ToModel()) : null;
        }
        /// <summary>
        /// Commands this instance.
        /// </summary>
        /// <returns></returns>
        public PartialViewResult Command()
        {
            ViewBag.Permissions = _permissionRepository.GetListByUserAndSite(UserId, SiteId).ToModel();
            return PartialView();
        }
    }
}
